<template>
	<div>
		<div style="margin-top: 30px">
			<el-form ref="BaseSelfForm" :model="BaseSelfInfo" :rules="rules" label-position="left" label-width="100px">
				<el-form-item label="公司名" prop="bname">
					<el-input size="small" v-model="BaseSelfInfo.bname" placeholder="请输入公司名" style="width: 280px;"></el-input>
				</el-form-item>
				<el-form-item label="合作院系">
					<el-input size="small" v-model="BaseSelfInfo.dname" style="width: 180px;" disabled></el-input>
				</el-form-item>
				<el-form-item label="所在城市" prop="city">
					<el-input size="small" v-model="BaseSelfInfo.city" placeholder="请输入公司所在城市" style="width: 180px;"></el-input>
				</el-form-item>
				<el-form-item label="详细地址" prop="location">
					<el-input v-model="BaseSelfInfo.location" type="textarea" style="width: 350px;" 
					placeholder="请输入公司详细地址" :autosize="{ minRows: 2, maxRows: 4}"></el-input>
				</el-form-item>
				<el-form-item label="联系电话" prop="phone">
					<el-input v-model="BaseSelfInfo.phone" placeholder="请输入联系电话" style="width: 180px;"></el-input>
				</el-form-item>
				<el-form-item label="合作开始日期">
					<el-input size="small" v-model="BaseSelfInfo.startTime" style="width: 180px;" disabled></el-input>
				</el-form-item>
			</el-form>
		</div>
		<div class="formBtn">
			<el-button type="primary" @click="submit">提交</el-button>
		</div>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				baseSelf:[],
				BaseSelfInfo: {},
				rules:{
				    bname: [{required: true, message: '请输入公司名',trigger: 'blur'}],
				    city: [{required: true, message: '请输入公司所在城市', trigger: 'blur'}],
				    location: [{required: true, message: '请输入公司详细地址', trigger: 'blur'}],
				    phone: [{required: true, message: '请输入联系电话', trigger: 'blur'}],
				},
			}
		},
		mounted(){
			this.initBaseSelf();
		},
		methods:{
			initBaseSelf(){
				this.getRequest('/information/baseSelf/').then(resp => {
					if(resp) {
						this.baseSelf = resp;
						this.BaseSelfInfo = this.baseSelf[0];
					}
				})
			},
			clearAll(){
				this.declareInfo = {};
			},
			submit() {
				this.$refs['BaseSelfForm'].validate(valid => {
					if (valid) {
						this.$confirm('此操作将提交修改的基地信息, 是否继续?', '提示', {
							confirmButtonText: '确定',
							cancelButtonText: '取消',
							type: 'warning'
						}).then(() => {
							this.putRequest("/information/baseSelf/", this.BaseSelfInfo).then(resp => {
								if (resp) {
									this.initBaseSelf();
								}
							})
						}).catch(() => {
							this.$message({
								type: 'info',
								message: '已取消提交'
							});
						});
					}
				})
			},
		}
	}
</script>

<style scoped>
	.formBtn{
		margin-top: 50px;
		margin-left: 20px;
	}
</style>
